﻿namespace Police.Model.Serialization
{
    using System.Collections.Generic;
    using System.Linq;
    using global::Serialization;
    using WP7Contrib.Collections;

    [Serializer(typeof(ObservableCollection<PoliceForce>))]
    public sealed class SerializeObservableCollectionPoliceForce : ISerializeObject
    {
        public object[] Serialize(object target)
        {
            var collection = (ObservableCollection<PoliceForce>)target;
            return new object[] { collection.ToList() };
        }

        public object Deserialize(object[] data)
        {
            var tmp = (List<PoliceForce>)data[0];
            var collection = new ObservableCollection<PoliceForce>();
            tmp.ForEach(collection.Add);

            return collection;
        }
    }
}